package cn.gok.resp2.controller;

import cn.gok.resp2.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private User user;
    ModelAndView md=new ModelAndView();

    @RequestMapping(value = "/login")
    public ModelAndView Login(@RequestParam String name,@RequestParam String password){
        System.out.println(user);
        if (user.getName().equals(name)&&user.getPassword().equals(password)){
            md.addObject(user);
            md.setViewName("success");
            return md;
        }else {
            md.addObject("登入失败");
            md.setViewName("userregist");
            return md;
        }

    }


    @RequestMapping("/regist")
    public String regist(@RequestParam String name,@RequestParam String password,@RequestParam int phone,@RequestParam int age){
        //只要判断用户名有没有冲突
        if (!user.getName().equals(name)){
            return "注册成功 ";
        }
        return "注册失败 ";
    }


    @RequestMapping("/index")
    public ModelAndView index(){
        md.setViewName("userlogin");
        return md;
    }
}
